#include<iostream>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

int ncases;
string tmp;

void solve() 
{
	int number;
	vector<int> vec;
	istringstream iss(tmp);
	while(iss >> number)
		vec.push_back(number);
	vector<string> vstrings((int)vec.size());
	for(int i = 0; i < (int)vec.size(); ++i) {
		string d;
		cin >> d;
		vstrings[vec[i] - 1] = d;
	}

	if(ncases != 0) {
		cout << endl;
	}
	for(vector<string>::iterator it = vstrings.begin(); it != vstrings.end(); ++it)
		cout << *it << endl;
}

void read()
{
	cin >> ncases;
	
	while(ncases--) {
		getline(cin, tmp);	//Blank line
		getline(cin, tmp);	//Blank line
		getline(cin, tmp);	//Indexs
		solve();
	}
}

int main() 
{
	read();
	return 0;
}